<?php

namespace App\Http\Controllers;

//查看背包
use App\Common\Sql;

class ViewBag extends Base
{

    public function logic()
    {
        if (!isset($this->param['uid'])) {
            return $this->returnError(1, "please input uid");
        }
        $uid  = $this->param['uid'];
        $data = array();
        $row  = Sql::select('t_user_bag_info', [['uid', $uid], ['num', '>', 0]]);
        foreach ($row as $info) {
            $item = array();
            //获取物品的信息
            $item_info = $this->get_item_info((int)$info['item_id']);
            if ($item_info == false) {
                continue;
            } else {
                $type = (int)$item_info['type'];
                if ((int)$item_info['icon_id'] == 0) {
                    continue;
                }
                $item['id']   = (int)$info['item_id'];
                $item['type'] = $type;
                $item['name'] = $item_info['name'];
                $item['num']  = (int)$info['num'];
                if ($type == 2 || $type == 3) {
                    $item['reward'] = $item_info['reward'];
                } else if ($type == 4) {
                    return $this->returnError(2, "your bag is error");
                }
            }
            $data['item_list'][] = $item;
        }
        $row = Sql::select('t_user_discount_info', [['uid', $uid], ['status', 1]]);
        foreach ($row as $info) {
            $item = array();
            //获取物品的信息
            $item_info = $this->get_item_info((int)$info['item_id']);
            if ($item_info == false) {
                continue;
            } else {
                if ((int)$item_info['icon_id'] == 0) {
                    continue;
                }
                $type            = (int)$item_info['type'];
                $item['id']      = (int)$info['id'];
                $item['item_id'] = (int)$info['item_id'];
                $item['type']    = $type;
                $item['name']    = $item_info['name'];
                $item['sign']    = $info['sign'];
                /*if($type == 4) {
                    $businesses = explode(',',$item_info['business_list']);
                    foreach($businesses as $business) {
                        $business_info = $this->get_business_info((int)$business);
                        if($business_info == false) {
                            continue;
                        } else {
                            $item['bussinesses'][] = array('id' => (int)$business,'name' => $business_info['name']);
                        }
                    }
                }
                else {
                    $this->returnError(3, "type of the discount is error!");
                }*/
            }
            $data['discount_list'][] = $item;
        }
        $data['uid'] = $uid;
        return $this->returnData($data);
    }

}